import { getBossQcodeInfo, reportCreate } from '../../utils/networkRequest.js'
import { errorMsg } from '../../utils/tool.js'
Page({
  data: {
    // items: [
    //   {
    //     value: '0',
    //     // 选项文案
    //     name: '洗车快速检测',
    //   },
    //   {
    //     value: '1',
    //     name: '保养全面检测',
    //   },
    // ],
    checkedValue: "0",
    activeColor: '#3274f6',
    dataInfo: null,//车况检测信息
    mileage: "",//里程数
    qcode: null,

  },
  onLoad: function (r) {
    let self = this;
    let qcode = r.qc;
    if (qcode) {
      getBossQcodeInfo(r.qc, (r) => { 
        if (r.code == 0) {
          self.setData({
            dataInfo: r.data,
            mileage: r.data.auto.mileage ? r.data.auto.mileage : "",
            qcode: qcode
          })
        }else{
          errorMsg(r.message)
        }
      })
    }
  },
  //获取里程数
  getmileage: function (e) {
    this.setData({
      mileage: e.detail.value
    })
  },
  handleSelectChange({ detail }) {
    this.setData({
      checkedValue: detail.value
    })
  },
  //开始检查
  onSubmit: function () {
    let { qcode, mileage, checkedValue } = this.data; 
    console.log("--------------------- - - - - - -");
    console.log(mileage);
    reportCreate(qcode, mileage, checkedValue, ((r) => { 
       if(r.code==0){
         //报告生成成功
         wx.navigateTo({
           url: '../checkitem/checkitem?qc=' + qcode + '&report_id=' + r.data.report_id
         })
       }
    }))
  }
});